package com.lzy.controller;

import java.util.Arrays;
import java.util.Map;

import com.lzy.common.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.lzy.entity.SysOperLogEntity;
import com.lzy.service.ISysOperLogService;

/**
 * 操作日志记录
 *
 * @author lyw
 * @email lyw@gmail.com
 * @date 2023-02-03 11:41:09
 */
@Api(tags = "日志模块")
@RestController
@RequestMapping("/sysoperlog")
public class SysOperLogController {
    @Autowired
    private ISysOperLogService ISysOperLogService;

    /**
     * 列表
     */
    @PostMapping("/list")
    @ApiOperation(value = "日志列表")
    public R list(@RequestParam(value = "page", defaultValue = "1") Integer page,
                  @RequestParam(value = "limit", defaultValue = "10") Integer limit){
        Page<Map<String, Object>> result = new Page<>(page, limit);
        LambdaQueryWrapper<SysOperLogEntity> lqw = new LambdaQueryWrapper<>();
        IPage<Map<String, Object>> list = ISysOperLogService.selectPageList(result, lqw);
        return R.ok().put("page", list);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{operId}")
    @ApiOperation(value = "日志信息")
    public R info(@PathVariable("operId") Long operId){
		    SysOperLogEntity sysOperLog = ISysOperLogService.getById(operId);
        return R.ok().put("sysOperLog", sysOperLog);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation(value = "保存日志")
    public R save(@RequestBody SysOperLogEntity sysOperLog){
		    ISysOperLogService.save(sysOperLog);
        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "更新日志")
    public R update(@RequestBody SysOperLogEntity sysOperLog){
		    ISysOperLogService.updateById(sysOperLog);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperation(value = "删除日志")
    public R delete(@RequestBody Long[] operIds){
		    ISysOperLogService.removeByIds(Arrays.asList(operIds));
        return R.ok();
    }

}
